#pragma once

#include <QGraphicsView>
#include <QList>
#include <QtNetwork/QLocalSocket>
#include <QtNetwork/QLocalServer>
#include <QtCore/QStateMachine>

#include "animation.h"
#include "transitionbutton.h"
#include "giftpixmap.h"

class QGraphicsScene ;
class QGraphicsItem ;
class Pixmap ;
class Button ;
class QPaintEvent ;

class AnimationView : public QGraphicsView
{
	Q_OBJECT
public :
	AnimationView(QWidget *parent = 0);
	AnimationView( QGraphicsScene * scene, QWidget * parent = 0 );

	void addItem( QGraphicsItem *item );
	QList<Pixmap *>& getItems(){ return items ; }
	Button* getGiftBtn(){ return giftBtn ; }

protected:
	virtual void closeEvent(QCloseEvent * event);
	virtual void keyPressEvent(QKeyEvent * event);
	virtual void keyReleaseEvent(QKeyEvent * event);

protected slots:
	void on_newConnection();
	void on_readyRead();

private :
	QGraphicsScene *scene ;
	QList<Pixmap *> items ;
	Button *giftBtn ;
	QLocalSocket *suc_socket ;
	QLocalServer server ;
	QStateMachine states;

	bool isAlt ;

	quint32 flowerCount ;
	quint32 uid ;

	static const int bitmapNum = 64 ;

	void animationViewInit( );
	void generateState();
	QState* createChildState(QState* state, int duration);
};